// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   OrderChangeConfirmScrPanel.java

package com.boci.clientapp.orderstatus;

import com.boci.clientapp.main.*;
import com.boci.clientapp.orderstatus.action.OrderChangeAction;
import com.boci.clientapp.orderstatus.vo.OrderChangeReviewVO;
import com.boci.clientapp.orderstatus.vo.OrderStatusDetailVO;
import com.boci.common.constant.ClientAppConst;
import com.boci.common.ui.AbstractPanel;
import com.boci.common.util.*;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Locale;
import javax.swing.*;

// Referenced classes of package com.boci.clientapp.orderstatus:
//            OrderStatusScrPanel

public class OrderChangeConfirmScrPanel extends AbstractPanel
{

    public OrderChangeConfirmScrPanel(Locale pLocale, String pModuleName, String pScreenName)
    {
        super(pLocale, pScreenName, pScreenName);
        msgConf = ClientAppLoader.getMessagesConfigurator();
        initGUI();
        setText(pLocale);
    }

    public void setText(Locale pLocale)
    {
        super.setText(pLocale);
        setFont(pLocale);
        currentLocale = pLocale;
        lblReference.setText(msgConf.getUIMessages("ORDER_STATUS.REFERENCE_NO", pLocale));
        lblPalceOn.setText(msgConf.getUIMessages("ORDER_STATUS.PLACED_ON", pLocale));
        lblDuration.setText(msgConf.getUIMessages("ORDER_STATUS.DURATION", pLocale));
        lblOrderType.setText(msgConf.getUIMessages("ORDER_STATUS.ORDER_TYPE", pLocale));
        lblNewPrice.setText(msgConf.getUIMessages("ORDER_STATUS.NEW_PRICE", pLocale));
        lblPrice.setText(msgConf.getUIMessages("ORDER_STATUS.PRICE", pLocale));
        lblNewQuantity.setText(msgConf.getUIMessages("ORDER_STATUS.NEW_QUANTITY", pLocale));
        lblQuantity.setText(msgConf.getUIMessages("ORDER_STATUS.QUANTITY", pLocale));
        lblTransaction.setText(msgConf.getUIMessages("ORDER_STATUS.TRANSACTION", pLocale));
        lblSecurityCode.setText(msgConf.getUIMessages("ORDER_STATUS.CODE", pLocale));
        lblNameOfSecurity.setText(msgConf.getUIMessages("ORDER_STATUS.NAME", pLocale));
        lbltitle.setText(msgConf.getUIMessages("ORDER_STATUS.CHANGE_ORDER", pLocale));
        btnOK.setText(msgConf.getUIMessages("ORDER_STATUS.OK", pLocale));
        if(orderStatusDetailVO != null)
            refresh(orderStatusDetailVO);
        requestFocus();
    }

    private void setFont(Locale pLocale)
    {
        lbltitle.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblReference.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblPalceOn.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblDuration.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblOrderType.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblNewPrice.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblNewQuantity.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblPrice.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblQuantity.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblTransaction.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblSecurityCode.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblNameOfSecurity.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblReferenceValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblPlaceOnValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblDurationValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblOrderTypeValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblNewPriceValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblNewQualityValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblPriceValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblQualityValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblTransactionValue.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblSecurityCodeValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblNameOfSecurityValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        btnOK.setFont(ClientAppLoader.getBoldButtonFont(pLocale));
        lblMessage.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblMessage2.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
    }

    public void initGUI()
    {
        setPreferredSize(new Dimension(710, 218));
        setBackground(Color.WHITE);
        setLayout(null);
        int intYPosDiff = 16;
        int intYPos = 22;
        lblNameOfSecurity = new JLabel();
        lblNameOfSecurity.setHorizontalAlignment(4);
        lblNameOfSecurity.setBounds(10, intYPos, 120, 20);
        add(lblNameOfSecurity);
        lblNameOfSecurityValue = new JLabel();
        lblNameOfSecurityValue.setBounds(145, intYPos, 320, 20);
        add(lblNameOfSecurityValue);
        intYPos += intYPosDiff;
        lblSecurityCodeValue = new JLabel();
        lblSecurityCodeValue.setBounds(145, intYPos, 160, 20);
        add(lblSecurityCodeValue);
        lblSecurityCode = new JLabel();
        lblSecurityCode.setHorizontalAlignment(4);
        lblSecurityCode.setBounds(10, intYPos, 120, 20);
        add(lblSecurityCode);
        intYPos += intYPosDiff;
        lblTransaction = new JLabel();
        lblTransaction.setHorizontalAlignment(4);
        lblTransaction.setBounds(10, intYPos, 120, 20);
        add(lblTransaction);
        lblTransactionValue = new JLabel();
        lblTransactionValue.setForeground(Color.BLUE);
        lblTransactionValue.setBounds(145, intYPos, 160, 20);
        add(lblTransactionValue);
        intYPos += intYPosDiff;
        lblQualityValue = new JLabel();
        lblQualityValue.setBounds(145, intYPos, 160, 20);
        add(lblQualityValue);
        lblQuantity = new JLabel();
        lblQuantity.setHorizontalAlignment(4);
        lblQuantity.setBounds(10, intYPos, 120, 20);
        add(lblQuantity);
        intYPos += intYPosDiff;
        lblNewQualityValue = new JLabel();
        lblNewQualityValue.setBounds(145, intYPos, 160, 20);
        add(lblNewQualityValue);
        lblNewQuantity = new JLabel();
        lblNewQuantity.setHorizontalAlignment(4);
        lblNewQuantity.setBounds(10, intYPos, 120, 20);
        add(lblNewQuantity);
        intYPos += intYPosDiff;
        lblPrice = new JLabel();
        lblPrice.setHorizontalAlignment(4);
        lblPrice.setBounds(10, intYPos, 120, 20);
        add(lblPrice);
        lblPriceValue = new JLabel();
        lblPriceValue.setBounds(145, intYPos, 160, 20);
        add(lblPriceValue);
        intYPos += intYPosDiff;
        lblNewPrice = new JLabel();
        lblNewPrice.setHorizontalAlignment(4);
        lblNewPrice.setBounds(10, intYPos, 120, 20);
        add(lblNewPrice);
        lblNewPriceValue = new JLabel();
        lblNewPriceValue.setBounds(145, intYPos, 160, 20);
        add(lblNewPriceValue);
        intYPos += intYPosDiff;
        lblOrderTypeValue = new JLabel();
        lblOrderTypeValue.setBounds(145, intYPos, 160, 20);
        add(lblOrderTypeValue);
        lblOrderType = new JLabel();
        lblOrderType.setHorizontalAlignment(4);
        lblOrderType.setBounds(10, intYPos, 120, 20);
        add(lblOrderType);
        intYPos += intYPosDiff;
        lblDuration = new JLabel();
        lblDuration.setHorizontalAlignment(4);
        lblDuration.setBounds(10, intYPos, 120, 20);
        add(lblDuration);
        lblDurationValue = new JLabel();
        lblDurationValue.setBounds(145, intYPos, 160, 20);
        add(lblDurationValue);
        intYPos += intYPosDiff;
        lblPlaceOnValue = new JLabel();
        lblPlaceOnValue.setBounds(145, intYPos, 160, 20);
        add(lblPlaceOnValue);
        lblPalceOn = new JLabel();
        lblPalceOn.setHorizontalAlignment(4);
        lblPalceOn.setBounds(10, intYPos, 120, 20);
        add(lblPalceOn);
        intYPos += intYPosDiff;
        lblReference = new JLabel();
        lblReference.setHorizontalAlignment(4);
        lblReference.setBounds(10, intYPos, 120, 20);
        add(lblReference);
        lblReferenceValue = new JLabel();
        lblReferenceValue.setBounds(145, intYPos, 160, 20);
        add(lblReferenceValue);
        lbltitle = new JLabel();
        lbltitle.setBounds(13, 1, 125, 20);
        add(lbltitle);
        btnOK = new JButton();
        btnOK.setMargin(new Insets(2, 2, 2, 2));
        btnOK.setBounds(435, 130, 120, 25);
        btnOK.setActionCommand("CHANGE_CONFIRM_OK");
        btnOK.addActionListener(this);
        add(btnOK);
        lblMessage = new JLabel();
        lblMessage.setBounds(325, 80, 396, 20);
        add(lblMessage);
        lblMessage2 = new JLabel();
        lblMessage2.setBounds(325, 100, 396, 20);
        add(lblMessage2);
    }

    public void actionPerformed(ActionEvent e)
    {
        PerformanceLogger.startAppTimer();
        String strActionType = e.getActionCommand();
        OrderChangeAction orderChangeAction = new OrderChangeAction();
        orderChangeAction.doProcess(getInputValue(strActionType), strActionType);
        PerformanceLogger.stopAppTimer();
        PerformanceLogger.doLog((new StringBuilder()).append(getScreenName()).append(".").append(strActionType).toString());
    }

    public void refresh()
    {
        btnOK.requestFocus();
    }

    public void refresh(HashMap pInHashMap)
    {
        ResponseVO responseVO = (ResponseVO)pInHashMap.get("SELECTED_VO");
        if(responseVO == null)
            return;
        OrderStatusDetailVO orderStatusDetailVO = null;
        if(responseVO instanceof OrderStatusDetailVO)
        {
            orderStatusDetailVO = (OrderStatusDetailVO)responseVO;
            orderChangeReviewVO = (OrderChangeReviewVO)pInHashMap.get("ORDER_CHANGE_REVIEW_VO");
        } else
        {
            return;
        }
        strNewQty = (String)pInHashMap.get("NEW_QTY");
        strNewPrice = (String)pInHashMap.get("NEW_PRICE");
        strCcy = orderStatusDetailVO.getCurrency();
        updateNewInputValue();
        refresh(responseVO);
    }

    public void updateNewInputValue()
    {
        String strTmpCcy = msgConf.getUIMessages(strCcy, currentLocale);
        String strPrice = StringUtil.formatPriceValue(strNewPrice, strTmpCcy);
        String strQty = StringUtil.formatQtyValue(strNewQty);
        lblNewPriceValue.setText(strPrice);
        lblNewQualityValue.setText(strQty);
    }

    public void refresh(ResponseVO pResponseVO)
    {
        if(pResponseVO == null)
        {
            lblReferenceValue.setText("");
            lblPlaceOnValue.setText("");
            lblDurationValue.setText("");
            lblOrderTypeValue.setText("");
            lblNewPriceValue.setText("");
            lblNewQualityValue.setText("");
            lblPriceValue.setText("");
            lblQualityValue.setText("");
            lblTransactionValue.setText("");
            lblSecurityCodeValue.setText("");
            lblNameOfSecurityValue.setText("");
        } else
        if(pResponseVO instanceof OrderStatusDetailVO)
        {
            orderStatusDetailVO = (OrderStatusDetailVO)pResponseVO;
            if(orderChangeReviewVO != null)
                lblReferenceValue.setText(StringUtil.getReferenceNo(orderChangeReviewVO.getOrderId()));
            String strPlaceOnDate = orderStatusDetailVO.getPlacementDate();
            strPlaceOnDate = StringUtil.formatLastUpdatedDateTime(orderStatusDetailVO.getPlacementDate());
            strPlaceOnDate = strPlaceOnDate != null ? strPlaceOnDate : "";
            lblPlaceOnValue.setText(strPlaceOnDate);
            lblDurationValue.setText(msgConf.getUIMessages(orderStatusDetailVO.getOrderDuration(), currentLocale));
            lblOrderTypeValue.setText(msgConf.getUIMessages(orderStatusDetailVO.getOrderType(), currentLocale));
            if(isNoPriceOrderType(orderStatusDetailVO.getOrderType()))
            {
                lblPriceValue.setVisible(false);
                lblNewPriceValue.setVisible(false);
            } else
            {
                lblPriceValue.setVisible(true);
                lblNewPriceValue.setVisible(true);
            }
            updateNewInputValue();
            String strTmpCcy = msgConf.getUIMessages(orderStatusDetailVO.getCurrency(), currentLocale);
            String strPrice = StringUtil.formatPriceValue(orderStatusDetailVO.getPrice(), strTmpCcy);
            String strTempQty = orderStatusDetailVO.getOrderQuantity();
            if(strTempQty == null || strTempQty.length() == 0)
                strTempQty = orderStatusDetailVO.getOriginalQuantity();
            String strQty = StringUtil.formatQtyValue(strTempQty);
            lblPriceValue.setText(strPrice);
            lblQualityValue.setText(strQty);
            String strBuyOrSell = orderStatusDetailVO.getBuyOrSell();
            if(strBuyOrSell.equalsIgnoreCase("BUY"))
                lblTransactionValue.setForeground(Color.BLUE);
            else
            if(strBuyOrSell.equalsIgnoreCase("SELL"))
                lblTransactionValue.setForeground(Color.RED);
            lblTransactionValue.setText(msgConf.getUIMessages(strBuyOrSell, currentLocale));
            lblSecurityCodeValue.setText(orderStatusDetailVO.getSymbol());
            String strNameEng = orderStatusDetailVO.getName();
            String strNameChs = orderStatusDetailVO.getName_chs();
            String strNameChi = orderStatusDetailVO.getName_chi();
            if(currentLocale.equals(ClientAppConst.ZH_HK) && strNameChi != null && strNameChi.length() != 0)
                lblNameOfSecurityValue.setText(strNameChi);
            else
            if(currentLocale.equals(ClientAppConst.ZH_CN) && strNameChs != null && strNameChs.length() != 0)
                lblNameOfSecurityValue.setText(strNameChs);
            else
                lblNameOfSecurityValue.setText(strNameEng);
            lblMessage.setText(msgConf.getUIMessages("ORDER_STATUS.ORDER_CHANGE_CFM_1", currentLocale));
            String strTmp = msgConf.getUIMessages("ORDER_STATUS.ORDER_CHANGE_CFM_2", currentLocale);
            String strLastUpdateTime = (new StringBuilder()).append(getOrderChangeLastUpdateDateTimeStr()).append(".").toString();
            strTmp = strTmp.trim().length() != 0 ? (new StringBuilder()).append(strTmp).append(" ").append(strLastUpdateTime).toString() : strLastUpdateTime;
            lblMessage2.setText(strTmp);
        }
    }

    public HashMap getInputValue(String pActionType)
    {
        HashMap map = new HashMap();
        map.put("SELECTED_VO", orderStatusDetailVO);
        map.put("NEW_QTY", strNewQty);
        map.put("NEW_PRICE", strNewPrice);
        return map;
    }

    public boolean validate(String pActionType)
    {
        return true;
    }

    public String getOrderChangeLastUpdateDateTimeStr()
    {
        String strLastUpdateTime = "";
        ApplicationService appServ = ApplicationService.getInstance();
        OrderStatusScrPanel orderStatusScrPanel = (OrderStatusScrPanel)appServ.getMainPanel().getPanel("ORDER_STATUS_MODULE", "ORDER_STATUS_SCREEN");
        if(orderStatusScrPanel != null)
            strLastUpdateTime = orderStatusScrPanel.getOrderChangeLastUpdateDateTimeStr();
        return strLastUpdateTime;
    }

    public void setDefFocus()
    {
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                btnOK.requestFocus();
            }
        }
);
    }

    private boolean isNoPriceOrderType(String pOrderType)
    {
        boolean returnFlag = false;
        String strNoPriceTypes[] = ClientAppLoader.getNoPriceOrdTypes();
        int i = 0;
        do
        {
            if(i >= strNoPriceTypes.length)
                break;
            if(strNoPriceTypes[i].equals(pOrderType))
            {
                returnFlag = true;
                break;
            }
            i++;
        } while(true);
        return returnFlag;
    }

    private JLabel lblMessage2;
    private JLabel lblMessage;
    private JButton btnOK;
    private JLabel lbltitle;
    private JLabel lblNameOfSecurity;
    private JLabel lblNameOfSecurityValue;
    private JLabel lblSecurityCodeValue;
    private JLabel lblSecurityCode;
    private JLabel lblTransaction;
    private JLabel lblTransactionValue;
    private JLabel lblNewQualityValue;
    private JLabel lblNewQuantity;
    private JLabel lblQualityValue;
    private JLabel lblQuantity;
    private JLabel lblNewPrice;
    private JLabel lblNewPriceValue;
    private JLabel lblPrice;
    private JLabel lblPriceValue;
    private JLabel lblOrderTypeValue;
    private JLabel lblOrderType;
    private JLabel lblDuration;
    private JLabel lblDurationValue;
    private JLabel lblPlaceOnValue;
    private JLabel lblPalceOn;
    private JLabel lblReference;
    private JLabel lblReferenceValue;
    private Locale currentLocale;
    private MessagesConfigurator msgConf;
    private OrderStatusDetailVO orderStatusDetailVO;
    private OrderChangeReviewVO orderChangeReviewVO;
    private String strCcy;
    private String strNewPrice;
    private String strNewQty;

}
